package com.cutJar.util;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileFilter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
/**
 * 
 * <b>字符流的读写<b>
 * @author 威 
 * <br>2018年3月25日 下午6:16:10 
 *
 */
public class CharStream {
	public static BufferedReader getRead(File file){
		BufferedReader br = null ;
		try {
			br = new BufferedReader(new FileReader(file)) ;
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
		return br ;
	}
	
	//获取文件写入流
	public static BufferedWriter getWrite(File file){
		BufferedWriter bw = null ;
		try {
			bw = new BufferedWriter(new FileWriter(file)) ;
		} catch (IOException e) {
			e.printStackTrace();
		}
		return bw ;
	}
	public static void free(Object stream) throws IOException{
		if(stream instanceof BufferedReader && stream != null){
			((BufferedReader) stream).close();
		}else if(stream instanceof BufferedWriter && stream != null){
			((BufferedWriter) stream).close();
		}else{
			if(stream != null){
				System.out.println("关闭文件流异常：" + stream + "-" + stream.getClass().getName());
			}else System.out.println(stream+"为空");
			
		}
	}
}
